package net.blogways.ordermgr.common.service;

import java.util.Map;

import com.asiainfo.bpc.utils.ToolFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * @author wanghui
 *         Created on 2017/11/2.
 */
@Service
public class CodeToNameService {

  private final Logger log = (Logger) LoggerFactory.getLogger(getClass());



  public String code2Name(String tableName, String code, String typeName, String locale) throws Exception {

    CommonService commonService = (CommonService) ToolFactory.getInstance().getContext()
            .getBean("commonService");

    Map rs = commonService.getTypeNameByCode(tableName, code, typeName, locale, "");
    String resultName = "";
    if (rs != null && rs.size() > 0){
        resultName = rs.get(typeName).toString();
    }
    return resultName;
  }


  public String code2Name(String tableName, String code, String typeName, String locale,String dbRoute) throws Exception {

    CommonService commonService = (CommonService) ToolFactory.getInstance().getContext()
            .getBean("commonService");

    Map rs = commonService.getTypeNameByCode(tableName, code, typeName, locale, dbRoute);
    String resultName = "";
    if (rs != null && rs.size() > 0){
      resultName = rs.get(typeName).toString();
    }
    return resultName;
  }
}
